data = load('linearvskernelcca.txt');
time = load('linearvskernelcca_time.txt');

view1 = data(:,1:3); % extracting view 1
view2 = data(:,4:6); % extracting view 2


figure;
scatter3(view1(:,1),view1(:,2),view1(:,3)); % plotting view 1
hold;
scatter3(view2(:,1),view2(:,2),view2(:,3)); % plotting view 2

[A B R U V ] = canoncorr(view1,view2); % performing canonical correlation analaysis

% plotting the first 2 canonical directions
figure;
plot(U(:,1),U(:,2),'rx'); 
hold;
plot(V(:,1),V(:,2),'bo');
hold off;

% extracting first CCA component
time_view_1 = U(:,1);
time_view_2 = V(:,1);

% sorting based on the time
[sorted, index] = sort(time);

% plot 1 dimensional projection
figure;
plot(time_view_1(index), 'b')
hold on;
plot(time_view_2(index), 'r')


Mmax = 50;  % max. M (number of components in incomplete Cholesky decomp.)
reg = 1E-5; % regularization
kernel1 = {'gauss',1};   % kernel type and kernel parameter for data set 1
kernel2 = {'gauss',1};   % kernel type and kernel parameter for data set 2

% KCCA
[KU,KV,beta] = km_kcca(view1,view2,kernel1,kernel2,reg,'ICD',Mmax);

% plotting the 1 dimensional projection of the kernel cca
figure;
plot(KU(index),'r');
hold;
plot(KV(index),'b'); 
hold off;



